package com.zitangkou.common.global;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 全局请求参数类
 *
 * @author Deng Ningning
 * @version 1.0
 * @date 2020/8/14 17:32
 */
@Data
@Accessors(chain = true)
public class GlobalReq implements Serializable {
    /**
     * 分页页码
     */
    private Integer current;
    /**
     * 分页大小
     */
    private Integer size;
    /**
     * 模糊查询关键字
     */
    private String keyword;
    /**
     * 开始时间
     */
    private LocalDateTime startTime;
    /**
     * 结束时间
     */
    private LocalDateTime endTime;

    /**
     * MySQL 分页下标从 0 开始
     *
     * @return java.lang.Integer
     * @author Deng Ningning
     * @date 2020/9/1 12:56
     */
    public Integer getCurrent() {
        if (this.current == null || this.current <= 0) {
            current = ConstantValue.DEFAULT_CURRENT_PAGE;
        }
        if (this.size == null || this.size <= 0) {
            size = ConstantValue.DEFAULT_PAGE_SIZE;
        }
        return current;
    }

    public Integer getSize() {
        if (this.size == null || this.size <= 0) {
            size = ConstantValue.DEFAULT_PAGE_SIZE;
        }
        return size;
    }
}
